/*
 * TcpServer.cpp
 *
 *  Created on: Nov 9, 2012
 *      Author: root
 */

#include "Acceptor.h"

namespace zeus
{

Acceptor::Acceptor(IoService & io_service)
:_service(io_service),_listen_fd(0)
{

}

Acceptor::~Acceptor()
{
}

void Acceptor::listen(uint16 port)
{
	_listen_fd = socket::create_socket();

	socket::set_reuse_addr(_listen_fd,true);

	bzero(&_addr, sizeof _addr);
	_addr.sin_family = AF_INET;
	_addr.sin_addr.s_addr = htons(INADDR_ANY );
	_addr.sin_port = htons(port);

	socket::bind(_listen_fd,_addr);

	socket::listen(_listen_fd);
}

void Acceptor::accept(TcpSocket & peer,const AcceptHandler & handler)
{
	_service.start_accept_op<int32,TcpSocket,AcceptHandler>(_listen_fd,peer,handler);
}

} /* namespace zeus */
